<?php
namespace Managers;
use \Site\UserInfo as UserInfoEntity;

class UserInfo extends BaseManager{
    public function getAll(){
        return $this->getEntityManager()
                ->createQueryBuilder()
                ->select('n')
                ->from('Site\UserInfo', 'n')
                ->orderBy('n.id', '')
                ->getQuery()
                ->getResult();
    }

    public function getOne($id){
        return $this->getEntityManager()
                ->createQueryBuilder()
                ->select('n')
                ->from('Site\UserInfo', 'n')
                ->where('n.id = :id')
                ->getQuery()
                ->setParameters(array('id'=>$id))
                ->getSingleResult();
    }

    
    public function AddUser($array){
        $entity = new UserInfoEntity();
        $entity->setUser($array['id']);
        $entity->setName($array['name']);
        $entity->setLastName($array['last_name']);
        $entity->setEmail($array['email']);
        $entity->setAreas($array['areas']);
        
        if(!empty($_SESSION['avatar'])){

            $entity->setAvatar($_SESSION['avatar']);
        }
        $em = $this->getEntityManager();
        $em->persist($entity);
        $em->flush();
     }

   
}
